//
//  CYAccountSetViewController.m
//  cyydt
//
//  Created by chu on 2019/1/15.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYAccountSetViewController.h"
#import "AccountImageTableViewCell.h"
#import "AccountSettingTableViewCell.h"
#import "CYEditNicknameViewController.h"
#import "CYAddressModel.h"
#import "CYMinePickerView.h"
#import "CYSelCategaryView.h"
#import "SYPersonalNotViewController.h"
#import "CYChangeBackGroundImageViewController.h"

typedef NS_ENUM(NSUInteger, SelType) {
    SelType_sex,
    SelType_age,
    SelType_address,
    SelType_HangYe,
    SelType_ChuangYeTime,
    SelType_TouZiYuSuan
};

@interface CYAccountSetViewController ()<UITableViewDelegate, UITableViewDataSource,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    NSArray *_titles;
    NSArray *_images;
    
    NSString *_selectValue;
    int _age;
    
    NSInteger _sexInt;
    
    NSArray *_hangyeArr;
    NSArray *_touziyusuanArr;
}
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *sexArr;

@property (nonatomic, strong) UIDatePicker *datePicker;

@property (nonatomic, assign) SelType selType;

@property (strong, nonatomic) HXPhotoManager *manager;

@property (nonatomic, strong) NSMutableArray *addressArr;

@property (nonatomic, strong) NSMutableArray *categaryArr;



@end

@implementation CYAccountSetViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tableView reloadData];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _images = @[@"wd_gezl_bg", @"rezl_bg2", @"rezl_bg3", @"rezl_bg4", @"rezl_bg5", @"rezl_bg6", @"rezl_bg7", @"rezl_bg8"];

    _titles = @[@"手机号", @"昵称", @"性别", @"年龄", @"地区", @"感兴趣的行业", @"创业时期", @"投资预算", @"个人简介"];
//    _titles = @[@"请选择", @"昵称", @"性别", @"年龄", @"地区", @"感兴趣的行业", @"创业时期", @"投资预算", @"个人简介"];
    [self getAddress];
    [self getAllCategary];
    [self getStagesWithType:@"1"];
    [self getStagesWithType:@"2"];

    self.title = @"个人资料";
    [self.view addSubview:self.tableView];
    if (@available(iOS 11.0, *)) {
        self.tableView.estimatedSectionFooterHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 11;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 || indexPath.row == 10) {
        AccountImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountImageTableViewCell"];
        if (!cell) {
            cell = [[NSBundle mainBundle] loadNibNamed:@"AccountImageTableViewCell" owner:self options:nil][0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.row == 0) {
            cell.headTitle.text = @"头像";
            cell.imageViewWidthConstraint.constant = 60;
            [cell.headImage sd_setImageWithURL:[NSURL URLWithString:[YLUserInfo shareUserInfo].avatar] placeholderImage:[UIImage imageWithColor:[UIColor lightGrayColor] Size:cell.headImage.frame.size]];
            cell.headImage.layer.cornerRadius = cell.headImage.frame.size.height / 2;
            cell.headImage.layer.masksToBounds = YES;
        }else{
            cell.headTitle.text = @"个人主页背景";
            cell.imageViewWidthConstraint.constant = 110;
            cell.headImage.layer.cornerRadius = 0;
            if ([YLUserInfo shareUserInfo].background) {
                NSInteger tag = [[YLUserInfo shareUserInfo].background integerValue] - 1;
                if (tag >= _images.count) {
                    cell.headImage.image = [UIImage imageNamed:[_images lastObject]];
                }else{
                    cell.headImage.image = [UIImage imageNamed:_images[tag]];
                }
            }
            
            
        }
        return cell;
    }else{
        AccountSettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountSettingTableViewCell"];
        if (!cell) {
            cell = [[NSBundle mainBundle] loadNibNamed:@"AccountSettingTableViewCell" owner:self options:nil][0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.leftLabel.text = _titles[indexPath.row - 1];
        cell.rightLabel.textColor = RGBOF(0xC8C8C8);
        switch (indexPath.row) {
            case 1:
                {
                    if ([NSString stringIsNull:[YLUserInfo shareUserInfo].phone]) {
                        cell.rightLabel.text = @"去绑定";
                        cell.rightLabel.textColor = RGBOF(0xF43636);
                    }else{
                        cell.rightLabel.text = [YLUserInfo shareUserInfo].phone;
                        cell.rightLabel.textColor = RGBOF(0xC8C8C8);
                    }
                    
                }
                break;
            case 2:
                {
                    if ([NSString stringIsNull:[YLUserInfo shareUserInfo].nickname]) {
                        cell.rightLabel.text = @"请填写昵称";
                    }else{
                        cell.rightLabel.text = [YLUserInfo shareUserInfo].nickname;
                    }
                }
                break;
            case 3:
            {
                //性别
                if ([[YLUserInfo shareUserInfo].gender integerValue] == 1) {
                    cell.rightLabel.text = @"男";
                }else if ([[YLUserInfo shareUserInfo].gender integerValue] == 2){
                    cell.rightLabel.text = @"女";

                }else{
                    cell.rightLabel.text = @"请选择性别";
                }
            }
                break;
            case 4:
            {
                //年龄
                if ([NSString stringIsNull:[YLUserInfo shareUserInfo].birthday]) {
                    cell.rightLabel.text = @"请输入年龄";
                }else{
                    if (_age) {
                        cell.rightLabel.text = [NSString stringWithFormat:@"%d",_age];
                    }else{
                        cell.rightLabel.text = [NSString stringWithFormat:@"%d",[self getAgeWithBrithod:[YLUserInfo shareUserInfo].birthday]];
                    }
                }
            }
                break;
            case 5:
            {
                //地区
                if ([NSString stringIsNull:[YLUserInfo shareUserInfo].provinceName]) {
                    cell.rightLabel.text = @"请选择地区";
                }else{
                    cell.rightLabel.text = [NSString stringWithFormat:@"%@%@",[YLUserInfo shareUserInfo].provinceName,[YLUserInfo shareUserInfo].cityName];
                }
            }
                break;
            case 6:
            {
                //感兴趣的行业
                if ([NSString stringIsNull:[YLUserInfo shareUserInfo].industryId]) {
                    cell.rightLabel.text = @"请选择感兴趣的行业";
                }else{
                    NSArray *ids = [[YLUserInfo shareUserInfo].industryId componentsSeparatedByString:@","];
                    NSArray *arr = [YLUserInfo shareUserInfo].industry;
                    NSString *muStr= @"";
                    for (NSString *ID in ids) {
                        for (NSDictionary *dic in arr) {
                            if ([[dic[@"id"] stringValue] isEqualToString:ID]) {
                                muStr = [muStr stringByAppendingString:[NSString stringWithFormat:@"%@,",dic[@"name"]]];
                            }
                        }
                    }
                    if (muStr.length > 0) {
                        cell.rightLabel.text = [muStr substringToIndex:muStr.length - 1];
                    }else{
                        cell.rightLabel.text = @"";
                    }
                    
                }
            }
                break;
            case 7:
            {
                if ([NSString stringIsNull:[YLUserInfo shareUserInfo].stageName]) {
                    cell.rightLabel.text = @"请选择创业时期";
                }else{
                    cell.rightLabel.text = [YLUserInfo shareUserInfo].stageName;
                }
                
            }
                break;
            case 8:
            {
                if ([NSString stringIsNull:[[YLUserInfo shareUserInfo].investmentBudget stringValue]]) {
                    cell.rightLabel.text = @"请选择投资预算";
                }else{
                    if ([[YLUserInfo shareUserInfo].investmentBudget integerValue] == 10) {
                        cell.rightLabel.text = @"3万以下";
                    }else if ([[YLUserInfo shareUserInfo].investmentBudget integerValue] == 15){
                        cell.rightLabel.text = @"3-8万";
                    }else if ([[YLUserInfo shareUserInfo].investmentBudget integerValue] == 5){
                        cell.rightLabel.text = @"5-10万";
                    }else if ([[YLUserInfo shareUserInfo].investmentBudget integerValue] == 6){
                        cell.rightLabel.text = @"10-20万";
                    }else if ([[YLUserInfo shareUserInfo].investmentBudget integerValue] == 11){
                        cell.rightLabel.text = @"20万以上";
                    }else{
                        cell.rightLabel.text = @"全部";
                    }
                    
                }
                
            }
                break;
                case 9:
            {
                if ([NSString stringIsNull:[YLUserInfo shareUserInfo].yldescription]) {
                    cell.rightLabel.text = @"一句话介绍你自己";
                }else{
                    cell.rightLabel.text = [YLUserInfo shareUserInfo].yldescription;
                }

            }
                
            default:
                break;
        }
        return cell;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 || indexPath.row == 10) {
        return 80;
    }
    return 50;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0001f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger tag = indexPath.row;
    switch (tag) {
        case 0:
            {
                //头像
                [self hx_presentSelectPhotoControllerWithManager:self.manager didDone:^(NSArray<HXPhotoModel *> *allList, NSArray<HXPhotoModel *> *photoList, NSArray<HXPhotoModel *> *videoList, BOOL isOriginal, UIViewController *viewController, HXPhotoManager *manager) {
                    [UINavigationBar appearance].translucent = NO;
                    NSLog(@"block - all - %@",allList);
                    NSLog(@"block - photo - %@",photoList);
                    NSLog(@"block - video - %@",videoList);
                    if (photoList.count > 0) {
                        [self updatePhotoWithHXPhotoModel:[photoList firstObject]];
                    }
                } cancel:^(UIViewController *viewController, HXPhotoManager *manager) {
                    [UINavigationBar appearance].translucent = NO;
                    NSLog(@"block - 取消了");
                }];
            }
            break;
        case 1:
        {
            //手机号
        }
            break;
        case 2:
        {
            //昵称
            CYEditNicknameViewController *edit = [[CYEditNicknameViewController alloc] init];
            edit.title = @"昵称";
            [[AppDelegate sharedAppDelegate] pushViewController:edit];
        }
            break;
        case 3:
        {
            //性别
            [self showEditSex];
        }
            break;
        case 4:
        {
            //年龄
            [self showDate];
        }
            break;
        case 5:
        {
            //地区
            [self showAddress];
        }
            break;
        case 6:
        {
            //感兴趣的行业
            [self selHangYe];
        }
            break;
        case 7:
        {
            //创业时期
            [self selChuangYeShiQi];
        }
            break;
        case 8:
        {
            //投资预算
            [self selTouZiYuSuan];
        }
            break;
        case 9:
        {
            //个人简介
            SYPersonalNotViewController *person = [[SYPersonalNotViewController alloc] init];
            [[AppDelegate sharedAppDelegate] pushViewController:person];
        }
            break;
        case 10:
        {
            //个人背景
            CYChangeBackGroundImageViewController *back = [[CYChangeBackGroundImageViewController alloc] init];
            [[AppDelegate sharedAppDelegate] pushViewController:back];
        }
            break;

            
        default:
            break;
    }
}

#pragma mark - 上传图片
- (void)updatePhotoWithHXPhotoModel:(HXPhotoModel *)model{
    [model requestImageDataStartRequestICloud:^(PHImageRequestID iCloudRequestId, HXPhotoModel *model) {
        // 开始下载iCloud上照片的imageData
    } progressHandler:^(double progress, HXPhotoModel *model) {
        // iCloud下载进度
    } success:^(NSData *imageData, UIImageOrientation orientation, HXPhotoModel *model, NSDictionary *info) {
        // 获取成功
        NSLog(@"imageData.length - %ld",imageData.length);
        //将图片上传到服务器
        [EasyShowLodingView showLoding];
        NSString *str = @"file";
        NSString *urlString = [User_HOST stringByAppendingString:str];
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        if ([YLUserInfo isLogIn]) {
            [manager.requestSerializer setValue:[YLUserInfo shareUserInfo].token forHTTPHeaderField:@"usertoken"];
        }
        NSMutableDictionary *dic = [NSMutableDictionary new];
        dic[@"target"] = @1;
        //接收类型不一致请替换一致text/html或别的
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                             @"text/html",
                                                             @"image/jpeg",
                                                             @"image/png",
                                                             @"application/octet-stream",
                                                             @"text/json",
                                                             nil];
        [manager POST:urlString parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            NSData *imageDatas = imageData;
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            formatter.dateFormat = @"yyyyMMddHHmmss";
            NSString *str = [formatter stringFromDate:[NSDate date]];
            NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
            //上传的参数(上传图片，以文件流的格式)
            [formData appendPartWithFileData:imageDatas
                                        name:@"file"
                                    fileName:fileName
                                    mimeType:@"image/jpeg"];
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            //打印下上传进度
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [EasyShowLodingView hidenLoding];
            NSLog(@"responseObject--- %@",responseObject);
            //上传成功
            if ([responseObject[Response_code] integerValue] == Response_value) {
                if ([responseObject[@"data"] isKindOfClass:[NSArray class]]) {
                    NSArray *data = responseObject[@"data"];
                    if (data.count > 0) {
                        NSDictionary *dic = [data firstObject];
                        [self editAvaterWithFullPath:dic[@"fullpath"]];
                    }
                }
                
            }else if([responseObject[@"returnCode"] integerValue] == 4000){
                
            }else{
                [self.view makeToast:responseObject[@"returnMessage"] duration:1.5 position:CSToastPositionCenter];
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"error -- %@",error);
            [EasyShowLodingView hidenLoding];
            //上传失败
            [self.view makeToast:@"上传失败" duration:1.5 position:CSToastPositionCenter];
        }];
    } failed:^(NSDictionary *info, HXPhotoModel *model) {
        // 获取失败
    }];
    
}

#pragma mark - 修改头像
- (void)editAvaterWithFullPath:(NSString *)fullpath{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"user/upload"];
    NSDictionary *param = @{@"url":fullpath};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"修改用户信息 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                [[AppDelegate sharedAppDelegate] getUserInfosWithComplecation:^{
                    [self.tableView reloadData];
                }];
                
            }else{
                [self.view makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
    
}

#pragma mark - 性别
- (void)showEditSex{
    UIView *customView = [UIView new];
    customView.gk_size = CGSizeMake(kWindowW, 265);
    customView.backgroundColor = [UIColor whiteColor];
    
    [customView addSubview:[self creatTitleViewWithTitle:@"请选择性别"]];
    [customView addSubview:[self creatBottomViewWithFrame:CGRectMake(0, 265 - 75, kWindowW, 75) SelType:SelType_sex]];
    
    UIView *middleView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, kWindowW, 265 - 75 - 50)];
    NSArray *images = @[@"grzl_nan", @"grzl_nv"];
    NSArray *selimages = @[@"grzl_nanxz", @"grzl_nvxz"];
    NSArray *titles = @[@"男", @"女"];
    [self.sexArr removeAllObjects];
    for (int i = 0; i < 2; i++) {
        
        LPButton *btn = [[LPButton alloc] init];
        btn.style = LPButtonStyleTop;
        
        btn.frame =CGRectMake(i * (kWindowW / 2), 0, kWindowW / 2, 265 - 75 - 50);
//        [btn setImagePositionWithType:SSImagePositionTypeTop spacing:4];
        
        
        [btn setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:selimages[i]] forState:UIControlStateSelected];

        [btn setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
        if (i == 0) {
            [btn setTitleColor:RGBOF(0x5EA7FF) forState:UIControlStateSelected];
        }else{
            [btn setTitleColor:RGBOF(0xFF5353) forState:UIControlStateSelected];
        }
        [btn setTitle:titles[i] forState:UIControlStateNormal];
        btn.tag = i;
        [middleView addSubview:btn];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.sexArr addObject:btn];
    }
    [customView addSubview:middleView];

    
    [GKCover translucentCoverFrom:[UIApplication sharedApplication].keyWindow content:customView animated:YES showBlock:^{
        // 显示出来时的block
        NSLog(@"弹窗显示了，6不6");
    } hideBlock:^{
        // 移除后的block
        NSLog(@"弹窗消失了，555");
    }];
}

- (void)btnClick:(UIButton *)sender{
    _sexInt = sender.tag + 1;
    for (UIButton *btn in self.sexArr) {
        if (btn == sender) {
            btn.selected = YES;
        }else{
            btn.selected = NO;
        }
    }
}

#pragma mark - 日期选择器
- (void)showDate{
    UIView *customView = [UIView new];
    customView.gk_size = CGSizeMake(kWindowW, 305);
    customView.backgroundColor = [UIColor whiteColor];
    
    [customView addSubview:[self creatTitleViewWithTitle:@"请选择出生日期"]];
    [customView addSubview:[self creatBottomViewWithFrame:CGRectMake(0, 305 - 75, kWindowW, 75) SelType:SelType_age]];
    
    UIView *middleView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, kWindowW, 305 - 75 - 50)];
    [middleView addSubview:self.datePicker];
    [customView addSubview:middleView];
    
    [GKCover translucentCoverFrom:[UIApplication sharedApplication].keyWindow content:customView animated:YES showBlock:^{
        // 显示出来时的block
        NSLog(@"弹窗显示了，6不6");
    } hideBlock:^{
        // 移除后的block
        NSLog(@"弹窗消失了，555");
    }];
}

#pragma mark - 时间选择器的滚动响应事件
- (void)didSelectValueChanged:(UIDatePicker *)sender {
    // 读取日期：datePicker.date
    NSString *value = [self toStringWithDate:sender.date];
    _selectValue = value;
    NSLog(@"滚动完成后，执行block回调:%@", value);
    
    _age = [self getAgeWithBrithod:value];
    [self.tableView reloadData];
}

- (int)getAgeWithBrithod:(NSString *)birth1{
    NSString *birth = birth1;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    //生日
    NSDate *birthDay = [dateFormatter dateFromString:birth];
    //当前时间
    NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
    NSDate *currentDate = [dateFormatter dateFromString:currentDateStr];
    NSLog(@"currentDate %@ birthDay %@",currentDateStr,birth);
    NSTimeInterval time=[currentDate timeIntervalSinceDate:birthDay];
    int age = ((int)time)/(3600*24*365);
    NSLog(@"year %d",age);
    return age;
}

#pragma mark - 格式转换：NSDate --> NSString
- (NSString *)toStringWithDate:(NSDate *)date {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    switch (self.datePicker.datePickerMode) {
        case UIDatePickerModeTime:
            [dateFormatter setDateFormat:@"HH:mm"];
            break;
        case UIDatePickerModeDate:
            [dateFormatter setDateFormat:@"yyyy-MM-dd"];
            break;
        case UIDatePickerModeDateAndTime:
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
            break;
        case UIDatePickerModeCountDownTimer:
            [dateFormatter setDateFormat:@"HH:mm"];
            break;
        default:
            break;
    }
    NSString *destDateString = [dateFormatter stringFromDate:date];
    
    return destDateString;
}

#pragma mark - 格式转换：NSDate <-- NSString
- (NSDate *)toDateWithDateString:(NSString *)dateString {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    switch (self.datePicker.datePickerMode) {
        case UIDatePickerModeTime:
            [dateFormatter setDateFormat:@"HH:mm"];
            break;
        case UIDatePickerModeDate:
            [dateFormatter setDateFormat:@"yyyy-MM-dd"];
            break;
        case UIDatePickerModeDateAndTime:
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
            break;
        case UIDatePickerModeCountDownTimer:
            [dateFormatter setDateFormat:@"HH:mm"];
            break;
        default:
            break;
    }
    NSDate *destDate = [dateFormatter dateFromString:dateString];
    
    return destDate;
}

#pragma mark - 地址选择
- (void)showAddress{
    CYMinePickerView *headView = [[CYMinePickerView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 305) DataArr:self.addressArr components:2];
    headView.titleLable.text = @"请选择地区";
    headView.addressBlock = ^(CYAddressModel * _Nonnull province, CYCityModel * _Nonnull city) {
        NSLog(@"province.name -- %@",province.name);
        NSLog(@"city -- %@",city.name);
        [self editInfosWithParam:@{@"province":province.areaid, @"city":city.areaid}];
    };
    [GKCover translucentCoverFrom:[UIApplication sharedApplication].keyWindow content:headView animated:YES showBlock:^{
        // 显示出来时的block
        NSLog(@"弹窗显示了，6不6");
    } hideBlock:^{
        // 移除后的block
        NSLog(@"弹窗消失了，555");
    }];
}

#pragma mark - 选择感兴趣的行业
- (void)selHangYe{
    NSArray *nibView =  [[NSBundle mainBundle] loadNibNamed:@"CYSelCategaryView" owner:self options:nil];
    CYSelCategaryView *backView = [nibView objectAtIndex:0];
    backView.frame = CGRectMake(0, 0, kWindowW, 410);
    backView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
    backView.dataSourceArr = self.categaryArr;
    backView.singlOrMore = YES;
    __weak typeof(self)weakself = self;
    backView.duoxuanBlock = ^(NSArray * _Nonnull valueArr) {
        NSMutableArray *muArr = [NSMutableArray array];
        for (CYCategrayModel *model in valueArr) {
            [muArr addObject:[model.catid stringValue]];
        }
        NSString *value = [muArr componentsJoinedByString:@","];
        [weakself editInfosWithParam:@{@"industryId":value}];
    };

    [GKCover translucentCoverFrom:[UIApplication sharedApplication].keyWindow content:backView animated:YES showBlock:^{
        // 显示出来时的block
        NSLog(@"弹窗显示了，6不6");
    } hideBlock:^{
        // 移除后的block
        NSLog(@"弹窗消失了，555");
    }];
}

#pragma mark - 选择创业时期
- (void)selChuangYeShiQi{
    NSArray *arr = @[@"我想创业", @"正在创业", @"创业成功", @"创业失败"];
    CYMinePickerView *headView = [[CYMinePickerView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 305) DataArr:arr components:1];
    headView.titleLable.text = @"请选择创业时期";
    headView.otherBlock = ^(NSString * _Nonnull value, NSInteger index) {

        [self editInfosWithParam:@{@"stage":[NSNumber numberWithInteger:index + 1]}];
    };
    [GKCover translucentCoverFrom:[UIApplication sharedApplication].keyWindow content:headView animated:YES showBlock:^{
        // 显示出来时的block
        NSLog(@"弹窗显示了，6不6");
    } hideBlock:^{
        // 移除后的block
        NSLog(@"弹窗消失了，555");
    }];
}

#pragma mark - 选择创业时期
- (void)selTouZiYuSuan{
    NSArray *arr = @[@"全部", @"3万以下", @"3-8万", @"5-10万", @"10-20万", @"20万以上"];
    CYMinePickerView *headView = [[CYMinePickerView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 305) DataArr:arr components:1];
    headView.titleLable.text = @"请选择投资预算";
    headView.otherBlock = ^(NSString * _Nonnull value, NSInteger index) {
        NSInteger investmentBudget = 1;
        if (index == 0) {
            investmentBudget = 1;
        }else if (index == 1){
            investmentBudget = 10;
        }else if (index == 2){
            investmentBudget = 15;
        }else if (index == 3){
            investmentBudget = 5;
        }else if (index == 4){
            investmentBudget = 6;
        }else if (index == 5){
            investmentBudget = 11;
        }else{
            investmentBudget = 1;
        }
        [self editInfosWithParam:@{@"investmentBudget":[NSNumber numberWithInteger:investmentBudget]}];
    };
    [GKCover translucentCoverFrom:[UIApplication sharedApplication].keyWindow content:headView animated:YES showBlock:^{
        // 显示出来时的block
        NSLog(@"弹窗显示了，6不6");
    } hideBlock:^{
        // 移除后的block
        NSLog(@"弹窗消失了，555");
    }];
}

#pragma mark - TitleView
- (UIView *)creatTitleViewWithTitle:(NSString *)title{
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 50)];
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 49, kWindowW, 1)];
    lineView.backgroundColor = RGBOF(0xe3e3e3);
    [titleView addSubview:lineView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kWindowW / 2, 50)];
    label.center = CGPointMake(kWindowW / 2, 25);
    label.text = title;
    label.textColor = RGBOF(0x333333);
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:18];
    [titleView addSubview:label];
    
    UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [doneBtn setImage:[UIImage imageNamed:@"grzl_gb"] forState:UIControlStateNormal];
    [doneBtn addTarget:self action:@selector(closeCoverView:) forControlEvents:UIControlEventTouchUpInside];
    [doneBtn setFrame:CGRectMake(kWindowW - 40, 0, 40, 50)];
    [titleView addSubview:doneBtn];
    return titleView;
}

- (void)closeCoverView:(UIButton *)sender{
    [GKCover hide];
}

#pragma mark - DoneBtn
- (UIView *)creatBottomViewWithFrame:(CGRect)frame SelType:(SelType)selType{
    self.selType = selType;
    UIView *titleView = [[UIView alloc] initWithFrame:frame];
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 1)];
    lineView.backgroundColor = RGBOF(0xe3e3e3);
    [titleView addSubview:lineView];
    
    UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [doneBtn setTitle:@"确定" forState:UIControlStateNormal];
    [doneBtn setBackgroundColor:RGBOF(0xFF5353)];
    doneBtn.layer.cornerRadius = 45 / 2;
    doneBtn.layer.masksToBounds = YES;
    [doneBtn addTarget:self action:@selector(doneAction:) forControlEvents:UIControlEventTouchUpInside];
    [doneBtn setFrame:CGRectMake(20, 15, kWindowW - 40, 45)];
    [titleView addSubview:doneBtn];
    return titleView;
}

- (void)doneAction:(UIButton *)sender{
    [GKCover hide];

    if (self.selType == SelType_sex) {
        //修改性别
        [self editInfosWithParam:@{@"gender":[NSNumber numberWithInteger:_sexInt]}];
    }else if (self.selType == SelType_age){
        //修改年龄
        if (_selectValue) {
            [self editInfosWithParam:@{@"birthday":_selectValue}];
        }
    }
}

#pragma mark - 修改用户信息
- (void)editInfosWithParam:(NSDictionary *)param{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"user/update"];
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"修改用户信息 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                [[AppDelegate sharedAppDelegate] getUserInfosWithComplecation:^{
                    [self.tableView reloadData];
                }];
                
            }else{
                [self.view makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

#pragma mark - 获取地址
- (void)getAddress{
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"areas"];
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:nil ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取地址 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {

        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                if ([responseResult[@"data"] isKindOfClass:[NSArray class]]) {
                    NSArray *data = responseResult[@"data"];
                    [self.addressArr removeAllObjects];
                    for (NSDictionary *dic in data) {
                        CYAddressModel *model = [CYAddressModel mj_objectWithKeyValues:dic];
                        [self.addressArr addObject:model];
                    }
                }
            }else{

            }
        }
    }];
}

#pragma mark - 获取创业属性
- (void)getStagesWithType:(NSString *)type{
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"stages"];
    NSDictionary *param = @{@"type":type};
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取创业属性 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                if ([responseResult[@"data"] isKindOfClass:[NSArray class]]) {
                    
                }
            }else{
                
            }
        }
    }];
}

#pragma mark - 获取所有分类
- (void)getAllCategary{
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"categories"];
    NSDictionary *param = @{@"type":@3};
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取所有分类 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                if ([responseResult[@"data"] isKindOfClass:[NSArray class]]) {
                    NSArray *data = responseResult[@"data"];
                    [self.categaryArr removeAllObjects];
                    for (NSDictionary *dic in data) {
                        NSMutableDictionary *muDic = [NSMutableDictionary dictionaryWithDictionary:dic];
                        [muDic setObject:dic[@"name"] forKey:@"catname"];
                        [muDic setObject:dic[@"id"] forKey:@"catid"];
                        [muDic setObject:dic[@"childCates"] forKey:@"child"];
                        [muDic removeObjectForKey:@"id"];
                        [muDic removeObjectForKey:@"name"];
                        [muDic removeObjectForKey:@"childCates"];
                        CYCategrayModel *model = [CYCategrayModel modelWithDictionary:muDic];
                        [self.categaryArr addObject:model];
                    }
                }
            }else{
                
            }
        }
    }];
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowH - Height_NavBar) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BackGroundColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerNib:[UINib nibWithNibName:@"AccountImageTableViewCell" bundle:nil] forCellReuseIdentifier:@"AccountImageTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"AccountSettingTableViewCell" bundle:nil] forCellReuseIdentifier:@"AccountSettingTableViewCell"];
        
    }
    return _tableView;
}

- (NSMutableArray *)sexArr{
    if (!_sexArr) {
        _sexArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _sexArr;
}

- (NSMutableArray *)addressArr{
    if (!_addressArr) {
        _addressArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _addressArr;
}

- (NSMutableArray *)categaryArr{
    if (!_categaryArr) {
        _categaryArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _categaryArr;
}

- (UIDatePicker *)datePicker {
    if (!_datePicker) {
        _datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, kWindowW, 180)];

        _datePicker.backgroundColor = [UIColor whiteColor];
        _datePicker.datePickerMode = UIDatePickerModeDate;
        // 设置该UIDatePicker的国际化Locale，以简体中文习惯显示日期，UIDatePicker控件默认使用iOS系统的国际化Locale
        _datePicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CHS_CN"];
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        // 设置时间范围
//        if (_minDateStr) {
//            NSDate *minDate = [formatter dateFromString:_minDateStr];
//            _datePicker.minimumDate = minDate;
//        }
        
        NSString *date = [formatter stringFromDate:[NSDate date]];
        NSDate *maxDate = [formatter dateFromString:date];
        _datePicker.maximumDate = maxDate;
        
        // 把当前时间赋值给 _datePicker
        [_datePicker setDate:[NSDate date] animated:YES];
        
        // 滚动改变值的响应事件
        [_datePicker addTarget:self action:@selector(didSelectValueChanged:) forControlEvents:UIControlEventValueChanged];
    }
    return _datePicker;
}

- (HXPhotoManager *)manager
{
    if (!_manager) {
        _manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhoto];
        _manager.configuration.photoMaxNum = 1;
        _manager.configuration.deleteTemporaryPhoto = NO;
        _manager.configuration.saveSystemAblum = YES;
        _manager.configuration.creationDateSort = YES;
        _manager.configuration.supportRotation = NO;
        _manager.configuration.cameraCellShowPreview = NO;
        _manager.configuration.navBarBackgroudColor = [UIColor whiteColor];
        _manager.configuration.navigationTitleColor = [UIColor blackColor];
        
        _manager.configuration.originalNormalImageName = @"zpgl_fb_wxz";
        _manager.configuration.originalSelectedImageName = @"zpgl_fb_xz";

        _manager.configuration.navigationBar = ^(UINavigationBar *navigationBar, UIViewController *viewController) {
                [navigationBar setBackgroundImage:[UIImage imageNamed:@"APPCityPlayer_bannerGame"] forBarMetrics:UIBarMetricsDefault];
                navigationBar.barTintColor = [UIColor whiteColor];
                navigationBar.tintColor = [UIColor blackColor];
        };
        //        _manager.configuration.sectionHeaderTranslucent = NO;
//                _manager.configuration.navBarBackgroudColor = [UIColor redColor];
        //        _manager.configuration.sectionHeaderSuspensionBgColor = [UIColor redColor];
        //        _manager.configuration.sectionHeaderSuspensionTitleColor = [UIColor whiteColor];
        //        _manager.configuration.statusBarStyle = UIStatusBarStyleLightContent;
        //        _manager.configuration.selectedTitleColor = [UIColor redColor];
        
        //        _manager.configuration.requestImageAfterFinishingSelection = YES;
        
        __weak typeof(self) weakSelf = self;
        _manager.configuration.photoListBottomView = ^(HXDatePhotoBottomView *bottomView) {
        };
        _manager.configuration.previewBottomView = ^(HXDatePhotoPreviewBottomView *bottomView) {
        };
        _manager.configuration.albumListCollectionView = ^(UICollectionView *collectionView) {
            //            NSSLog(@"albumList:%@",collectionView);
        };
        _manager.configuration.photoListCollectionView = ^(UICollectionView *collectionView) {
            //            NSSLog(@"photoList:%@",collectionView);
        };
        _manager.configuration.previewCollectionView = ^(UICollectionView *collectionView) {
            //            NSSLog(@"preview:%@",collectionView);
        };
        //        _manager.configuration.movableCropBox = YES;
        //        _manager.configuration.movableCropBoxEditSize = YES;
        //        _manager.configuration.movableCropBoxCustomRatio = CGPointMake(1, 1);
        
        // 使用自动的相机  这里拿系统相机做示例
        _manager.configuration.shouldUseCamera = ^(UIViewController *viewController, HXPhotoConfigurationCameraType cameraType, HXPhotoManager *manager) {
            
            // 这里拿使用系统相机做例子
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            imagePickerController.delegate = (id)weakSelf;
            imagePickerController.allowsEditing = NO;
            NSString *requiredMediaTypeImage = ( NSString *)kUTTypeImage;
            NSString *requiredMediaTypeMovie = ( NSString *)kUTTypeMovie;
            NSArray *arrMediaTypes;
            if (cameraType == HXPhotoConfigurationCameraTypePhoto) {
                arrMediaTypes=[NSArray arrayWithObjects:requiredMediaTypeImage,nil];
            }else if (cameraType == HXPhotoConfigurationCameraTypeVideo) {
                arrMediaTypes=[NSArray arrayWithObjects:requiredMediaTypeMovie,nil];
            }else {
                arrMediaTypes=[NSArray arrayWithObjects:requiredMediaTypeImage, requiredMediaTypeMovie,nil];
            }
            [imagePickerController setMediaTypes:arrMediaTypes];
            // 设置录制视频的质量
            [imagePickerController setVideoQuality:UIImagePickerControllerQualityTypeHigh];
            //设置最长摄像时间
            [imagePickerController setVideoMaximumDuration:60.f];
            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            imagePickerController.navigationController.navigationBar.tintColor = [UIColor whiteColor];
            imagePickerController.modalPresentationStyle=UIModalPresentationOverCurrentContext;
            [viewController presentViewController:imagePickerController animated:YES completion:nil];
        };
        //        _manager.shouldSelectModel = ^NSString *(HXPhotoModel *model) {
        //            // 如果return nil 则会走默认的判断是否达到最大值
        //            //return nil;
        //            return @"Demo1 116 - 120 行注释掉就能选啦~\(≧▽≦)/~";
        //        };
        _manager.configuration.videoCanEdit = NO;
        _manager.configuration.photoCanEdit = YES;
    }
    return _manager;
}

@end
